<?php
@set_time_limit(0);  //若配置为 0 则不限定最久时间
//error_reporting(E_ALL);
if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}
@ require ('writable/set/set_area.php');
@ require ('readonly/function/write_file.php');
$persistent = 1;
/*
$ev='
$content_t = preg_replace("/column\.php\?column_id=(\w+)/i", "column_\$1.html", $content_t);
$content_t = preg_replace("/class\.php\?column_id=(\w+)(&|&amp;)class_id=(\d+)/i", "class_\$1_\$3.html", $content_t);
';
*/

echo '<span class="grayword">正在生成<b>首页</b> - index.html</span> ';
@ob_flush();
@flush();

$web['html'] = true;
echo reset_indexhtml('index.php', 'index.html') ? '成功<br />' : '失败<br />';

@ob_flush();
@flush();


unset($_GET);

$text_correct = $column_py = '';

foreach ((array)$web['area'] as $column_id => $column) {
  //$column = (array)$column;
  $_GET['column_id'] = $column_id;
  $column_py = $column['name'][1];
  echo '<br /><span class="grayword">正在生成频道：<b>'.$column['name'][0].'</b> - '.$column_py.'.html</span> ';
  @ob_flush();
@flush();

  $web['html'] = true;
  echo reset_indexhtml('column.php', $column_py.'.html') ? '成功<br />' : '失败<br />';
  @ob_flush();
@flush();


  $web['area'][$_GET['column_id']]['name'][0] = $column['name'][0];
  $web['area'][$_GET['column_id']]['name'][1] = $column['name'][1];
  unset($column['name']);
  foreach ($column as $class_id => $class) {
    $_GET['class_id'] = $class_id;
    echo '<span class="grayword">&nbsp;&nbsp;&nbsp;&nbsp;正在生成栏目：<b>'.$class[0].'</b> - '.$column_py.'_'.$class[1].'.html</span> ';
    @ob_flush();
@flush();

    $web['html'] = true;
    echo reset_indexhtml('class.php', $column_py.'_'.$class[1].'.html') ? '成功<br />' : '失败<br />';
    @ob_flush();
@flush();

  }
  //unset($_GET, $column_py);
}

//生成专题
$priority_arr = array();
if (!isset($sql['db_err'])) {
  $db = db_conn();
}
if ($sql['db_err'] == '') {

  $result = db_query($db, 'SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE detail_title<>"" AND http_name_style="" AND class_priority<>"" GROUP BY detail_title');
  if ($result != false) {
    while ($row = db_fetch($db, $result)) {

      //if (array_key_exists($row['column_id'], $web['area']) && array_key_exists($row['class_id'], $web['area'][$row['column_id']])) {
      if (isset($web['area'][$row['column_id']]) && isset($web['area'][$row['column_id']][$row['class_id']])) {
        $priority_arr[$row['column_id'].'_'.$row['class_id'].'_'.$row['detail_title']] = 1;
      }
      unset($row);
    }
  }
  $result = NULL;

}/* else {
  $err .= $sql['db_err'];
}*/
db_close($db);

unset($_GET);
if (count($priority_arr) > 0) {
  echo '<br /><b>正在生成专题…</b><br />';
  @ob_flush();
@flush();

  foreach ($priority_arr as $priority_key => $priority_val) {
    list($_GET['column_id'], $_GET['class_id'], $detail_title) = @explode('_', $priority_key);
    list($_GET['detail_title'], $detail_py, ) = @explode('|', $detail_title);
    $web['html'] = true;
    reset_indexhtml('detail.php', $detail_py.'.html');
	echo '<span class="grayword">专题：<b>'.$_GET['detail_title'].'</b> - '.$detail_py.'.html</span> 成功！<br />';
    unset($_GET, $detail_title ,$detail_py);
    @ob_flush();
@flush();

  }
}

write_file('writable/set/set_html.php', '<?php $web[\'html\'] = true; ?>');

echo '<script>
function scrollToBottom() {
  //window.scrollTo(0, document.body.offsetHeight);
  location.href="#htmlend";
}
if(document.all){
  window.attachEvent("onload",scrollToBottom);
}else{
  window.addEventListener("load",scrollToBottom,false);
}
</script>';
alert('全站静态执行完毕（请刷新一下首页，如果生成未完全成功，请<a href="javascript:location.reload();">刷新一下本页面</a>）<a name="htmlend" id="htmlend"></a>！', 'webmaster_central.php');


?>